﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.DocentIncheckingen;
using HROReporting.Infrastructure.UnitOfWork;
using NHibernate;
using HROReporting.Infrastructure.Querying;
using NHibernate.Criterion;
using HROReporting.Model.Docenten;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class DocentIncheckingRepository : Repository<DocentInchecking, int>, IDocentIncheckingRepository
    {
        public DocentIncheckingRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public DocentInchecking GetDocentIncheckingByDocentCode(string docentCode)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(DocentInchecking))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<DocentInchecking>
                (d => d.DocentCode), docentCode));

            IList<DocentInchecking> docentIncheckingen = criteriaQuery.List<DocentInchecking>();
            DocentInchecking docentInchecking = docentIncheckingen.FirstOrDefault();

            return docentInchecking;
        }

        public IEnumerable<Presentielijst> GetPresentielijstenBySerial(string serial)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(Presentielijst))
                .CreateAlias("NFCDevice", "NFCDevice")
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<Presentielijst>
                (d => d.NFCDevice.NFCDeviceSerial), serial));

            IList<Presentielijst> presentielijsten = criteriaQuery.List<Presentielijst>();

            return presentielijsten;
        }


        public IEnumerable<DocentInchecking> GetDocentIncheckingenByDocentCode(string docentCode)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(DocentInchecking))
                .CreateAlias("SchoolLocatie", "SchoolLocatie")
                .CreateAlias("SchoolKantoor", "SchoolKantoor")
                .CreateAlias("SchoolLokaal", "SchoolLokaal")
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<DocentInchecking>
                (d => d.DocentCode), docentCode));

            IList<DocentInchecking> docentIncheckingen = criteriaQuery.List<DocentInchecking>();

            return docentIncheckingen;
        }
    }
}
